#include "StdAfx.h"
#include "CircleEditor.h"
#include "EditorHelper.h"
#include "./FunctionDrivers/FunctionDriverCircle.h"

REGISTERE_EDITOR(CCircleEditor);

CCircleEditor::CCircleEditor(void)
{

}

CCircleEditor::~CCircleEditor(void)
{
}

CString CCircleEditor::GetID(void)
{
	return CIRCLE_CP_GUID;
}

CCircleInfo* CCircleEditor::GetShapeInfo()
{
	return &m_Info;
}

void CCircleEditor::Initialize(CAnyView* pView)
{
	m_Info.Reset();

	AddSubEditor(new CPointCapture(m_Info.ptCenter),
		CCircleInfo::CENTER_POINT);
	AddSubEditor(new CLengthCapture(m_Info.ptCenter, m_ptEnd, m_Info.dRadius),
		CCircleInfo::RADIUS);

	CModelEditor::Initialize(pView);

	m_Info.dirNormal = pView->CurPlaneNormal();
}

bool CCircleEditor::CreatePreviewShape(void)
{
	if(CurrentStep()==CCircleInfo::CENTER_POINT)
		return false;

	TopoDS_Shape shape;
	CCircleBuilder builder;
	if(builder.Build(&m_Info, shape))
	{
		SetPreviewShape(shape);
		return true;
	}

	return false;
}

bool CCircleEditor::CreateShapeLabel(TDF_Label& label)
{
	label = NewLabel(_T("Circle"));

	m_Info.AddToLabel(label);

	Handle(CFunctionDriverCircle) functionDriver;
	return ProcessFunctionDriver<CFunctionDriverCircle>(label, functionDriver);
}
